﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TrainingWorkshop.Models;

namespace TrainingWorkshop.DAL
{
    public class GetLevel
    {
        GetConnection cn = new GetConnection();
        SqlConnection con = new SqlConnection();
        public List<Level> GetAllLevel()
        {
            string sql = "select distinct * from Level";
            con = cn.ConnectDatabase();
            List <Level> levellist=new List<Level>();
            try
            {
                con.Open();
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                da.Fill(ds, "Level");
                foreach(DataRow row in ds.Tables[0].Rows)
                {
                    Level level = new Level();
                    level.LevelId = Convert.ToInt32(row[0].ToString().Trim());
                    level.LevelName = row[1].ToString().Trim();
                    levellist.Add(level);
                }
                return levellist;
            }
            finally
            {
                con.Close();
            }
        }
        
    }
}
